#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <arpa/inet.h>
#include <sys/socket.h>
int main(){
    //创建套接字
    int sock = socket(PF_INET, SOCK_STREAM, 0);
    //向服务器（特定的IP和端口）发起请求
    struct sockaddr_in serv_addr;
    memset(&serv_addr, 0, sizeof(serv_addr));  //每个字节都用0填充
    serv_addr.sin_family = AF_INET;  //使用IPv4地址
    serv_addr.sin_addr.s_addr = inet_addr("127.0.0.1");  //具体的IP地址
    //作用同：inet_aton("127.0.0.1",&serv_addr.sin_addr);
    serv_addr.sin_port = htons(1234);  //端口
    connect(sock, (struct sockaddr*)&serv_addr, sizeof(serv_addr));
   
    //读取服务器传回的数据
    char buffer[40];
    //验证tcp的传输无数据边界
    int str_len=0,idx=0,read_len = 0;
    // while(read_len = read(sock,&buffer[idx++],1))
    // {
    //     str_len+=read_len;
    //     //printf("%d\n",str_len);
    // }
    // busy waiting!!
    int wait = 0;
    for(wait=0; wait<3000; wait++)		
		printf("Wait time %d \n", wait);
    read(sock, buffer, sizeof(buffer));
   
    printf("Message form server: %s\n", buffer);
    //printf("Call Count: %d\n", str_len);
   
    //关闭套接字
    close(sock);
    return 0;
}
